﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KinConquer.Entities.Calculations
{
    public class Misc
    {
        public static Int32 Distance(UInt16 x, UInt16 y, UInt16 x2, UInt16 y2)
        {
            return (Int32)Math.Max(Math.Abs(x - x2), Math.Abs(y - y2));
        }

        public static Byte Angle(UInt16 x, UInt16 y, UInt16 x2, UInt16 y2)
        {
            return ((Byte)((Byte)(7 - (Math.Floor(PointDirecton(x, y, x2, y2) / 45 % 8)) - 1 % 8) % 8));
        }
        public static Double PointDirecton(Double x1, Double y1, Double x2, Double y2)
        {
            Double direction = 0;
            Double AddX = x2 - x1;
            Double AddY = y2 - y1;
            Double r = (Double)Math.Atan2(AddY, AddX);
            if (r < 0) r += (Double)Math.PI * 2;
            direction = 360 - (r * 180 / (Double)Math.PI);
            return direction;
        }
    }
}
